package com.hailin.pigauth.controller;

import com.hailin.pigapi.common.Result;
import com.hailin.pigapi.model.auth.UserInfoDto;
import com.hailin.pigapi.request.auth.UserInfoRequest;
import com.hailin.pigapi.request.auth.UserRegistRequest;
import com.hailin.pigauth.service.PigAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/pigAuth")
public class PigAuthController {

    @Autowired
    private PigAuthService pigAuthService;

    /**
     * 用户登录
     * @param userInfoRequest
     * @return
     */
    @PostMapping("/login")
    public Result login(@ModelAttribute UserInfoRequest userInfoRequest){
        return pigAuthService.login(userInfoRequest);
    }

    /**
     * 用户注册
     * @param userRegistRequest
     * @return
     */
    @PostMapping("/regist")
    public Result regist(@ModelAttribute UserRegistRequest userRegistRequest){
        return pigAuthService.regist(userRegistRequest);
    }

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @GetMapping("/getUserById")
    public Result<UserInfoDto> getUserById(@RequestParam String userId){
        Result<UserInfoDto> userInfoDto = pigAuthService.getUserById(userId);
        return userInfoDto;
    }

}
